import wx
import wx.xrc
import wmi
import platform
import psutil


class MyFrame_PC_info(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, id=wx.ID_ANY, title='我的计算机', pos=wx.DefaultPosition,
                          size=wx.Size(800, 600), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)

        self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
        self.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT))

        MyComputer = wx.BoxSizer(wx.VERTICAL)

        MyComputer.Add((0, 0), 1, wx.EXPAND, 5)

        bSizer2 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer2.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText1 = wx.StaticText(self, wx.ID_ANY, u"计算机名称", wx.DefaultPosition, wx.Size(200, -1), 0)
        self.m_staticText1.Wrap(-1)

        bSizer2.Add(self.m_staticText1, 0, wx.ALL, 5)

        self.computer_name = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(300, -1), 0)
        self.computer_name.Wrap(-1)

        bSizer2.Add(self.computer_name, 0, wx.ALL, 5)

        bSizer2.Add((0, 0), 1, wx.EXPAND, 5)

        MyComputer.Add(bSizer2, 1, wx.EXPAND, 5)

        bSizer21 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer21.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText11 = wx.StaticText(self, wx.ID_ANY, u"计算机操作系统", wx.DefaultPosition, wx.Size(200, -1), 0)
        self.m_staticText11.Wrap(-1)

        bSizer21.Add(self.m_staticText11, 0, wx.ALL, 5)

        self.computer_OS = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(300, -1), 0)
        self.computer_OS.Wrap(-1)

        bSizer21.Add(self.computer_OS, 0, wx.ALL, 5)

        bSizer21.Add((0, 0), 1, wx.EXPAND, 5)

        MyComputer.Add(bSizer21, 1, wx.EXPAND, 5)

        bSizer22 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer22.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText12 = wx.StaticText(self, wx.ID_ANY, u"域名", wx.DefaultPosition, wx.Size(200, -1), 0)
        self.m_staticText12.Wrap(-1)

        bSizer22.Add(self.m_staticText12, 0, wx.ALL, 5)

        self.domain = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(300, -1), 0)
        self.domain.Wrap(-1)

        bSizer22.Add(self.domain, 0, wx.ALL, 5)

        bSizer22.Add((0, 0), 1, wx.EXPAND, 5)

        MyComputer.Add(bSizer22, 1, wx.EXPAND, 5)

        bSizer23 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer23.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText13 = wx.StaticText(self, wx.ID_ANY, u"系统制造商", wx.DefaultPosition, wx.Size(200, -1), 0)
        self.m_staticText13.Wrap(-1)

        bSizer23.Add(self.m_staticText13, 0, wx.ALL, 5)

        self.system_manufacturer = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(300, -1), 0)
        self.system_manufacturer.Wrap(-1)

        bSizer23.Add(self.system_manufacturer, 0, wx.ALL, 5)

        bSizer23.Add((0, 0), 1, wx.EXPAND, 5)

        MyComputer.Add(bSizer23, 1, wx.EXPAND, 5)

        bSizer24 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer24.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText14 = wx.StaticText(self, wx.ID_ANY, u"系统型号", wx.DefaultPosition, wx.Size(200, -1), 0)
        self.m_staticText14.Wrap(-1)

        bSizer24.Add(self.m_staticText14, 0, wx.ALL, 5)

        self.system_model = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(300, -1), 0)
        self.system_model.Wrap(-1)

        bSizer24.Add(self.system_model, 0, wx.ALL, 5)

        bSizer24.Add((0, 0), 1, wx.EXPAND, 5)

        MyComputer.Add(bSizer24, 1, wx.EXPAND, 5)

        bSizer25 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer25.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText15 = wx.StaticText(self, wx.ID_ANY, u"处理器数", wx.DefaultPosition, wx.Size(200, -1), 0)
        self.m_staticText15.Wrap(-1)

        bSizer25.Add(self.m_staticText15, 0, wx.ALL, 5)

        self.process_count = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(300, -1), 0)
        self.process_count.Wrap(-1)

        bSizer25.Add(self.process_count, 0, wx.ALL, 5)

        bSizer25.Add((0, 0), 1, wx.EXPAND, 5)

        MyComputer.Add(bSizer25, 1, wx.EXPAND, 5)

        bSizer26 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer26.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText16 = wx.StaticText(self, wx.ID_ANY, u"处理器", wx.DefaultPosition, wx.Size(200, -1), 0)
        self.m_staticText16.Wrap(-1)

        bSizer26.Add(self.m_staticText16, 0, wx.ALL, 5)

        self.processor = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(300, -1), 0)
        self.processor.Wrap(-1)

        bSizer26.Add(self.processor, 0, wx.ALL, 5)

        bSizer26.Add((0, 0), 1, wx.EXPAND, 5)

        MyComputer.Add(bSizer26, 1, wx.EXPAND, 5)

        bSizer27 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer27.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText17 = wx.StaticText(self, wx.ID_ANY, u"内存", wx.DefaultPosition, wx.Size(200, -1), 0)
        self.m_staticText17.Wrap(-1)

        bSizer27.Add(self.m_staticText17, 0, wx.ALL, 5)

        self.memory = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(300, -1), 0)
        self.memory.Wrap(-1)

        bSizer27.Add(self.memory, 0, wx.ALL, 5)

        bSizer27.Add((0, 0), 1, wx.EXPAND, 5)

        MyComputer.Add(bSizer27, 1, wx.EXPAND, 5)

        bSizer28 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer28.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText18 = wx.StaticText(self, wx.ID_ANY, u"剩余物理地址", wx.DefaultPosition, wx.Size(200, -1), 0)
        self.m_staticText18.Wrap(-1)

        bSizer28.Add(self.m_staticText18, 0, wx.ALL, 5)

        self.memory_remain = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(300, -1), 0)
        self.memory_remain.Wrap(-1)

        bSizer28.Add(self.memory_remain, 0, wx.ALL, 5)

        bSizer28.Add((0, 0), 1, wx.EXPAND, 5)

        MyComputer.Add(bSizer28, 1, wx.EXPAND, 5)

        MyComputer.Add((0, 0), 1, wx.EXPAND, 5)

        self.SetSizer(MyComputer)
        self.Layout()

        self.Centre(wx.BOTH)
        self.update_label()

    # TODO:必须 背下来！！！！！！！！！！！
    def update_label(self):
        # 计算机名称
        m_computer_name = platform.node()
        m_computer_OS = platform.system()
        c = wmi.WMI()
        m_domain = c.Win32_ComputerSystem()[0].Domain
        m_system_manufacturer = c.Win32_ComputerSystem()[0].Manufacturer
        m_system_model = c.Win32_ComputerSystem()[0].Model
        m_processor_count = c.Win32_Processor()[0].NumberOfCores
        m_processor_count = str(m_processor_count)
        m_processor = c.Win32_Processor()[0].Name

        m_memory_all = psutil.virtual_memory()
        m_memory = str(round(m_memory_all.total / 1024 / 1024, 2)) + "MB"
        m_memory_remain = str(round(m_memory_all.free / 1024 / 1024, 3)) + "MB"

        self.computer_name.SetLabel(m_computer_name)
        self.computer_OS.SetLabel(m_computer_OS)
        self.domain.SetLabel(m_domain)
        self.system_manufacturer.SetLabel(m_system_manufacturer)
        self.system_model.SetLabel(m_system_model)
        self.process_count.SetLabel(str(m_processor_count))
        self.processor.SetLabel(m_processor)
        self.memory.SetLabel(m_memory)
        self.memory_remain.SetLabel(m_memory_remain)

    def __del__(self):
        pass


app = wx.App(False)
frame = MyFrame_PC_info(None)
frame.Show(True)
app.MainLoop()
